//Sprite Class

//The dot that will move around on the screen class 
Dot { 
    private: 
    //The X and Y offsets of the dot 
    int x, y; 

    //The velocity of the dot 
    int xVel, yVel; 

    public: 
    //Initializes the variables 
    Dot(); 

    //Takes key presses and adjusts the dot's velocity 
    void handle_input(); 

    //Shows the dot on the screen void 
    show(); 
};

Dot::Dot() 
{ 
  //Initialize the offsets 
  x = 0; 
  y = 0; 

  //Initialize the velocity 
  xVel = 0; 
  yVel = 0; 
}

void Dot::handle_input()
{
    //If a key was pressed
    if( event.type == SDL_KEYDOWN )
    {
        //Adjust the velocity
        switch( event.key.keysym.sym )
        {
            case SDLK_UP: yVel -= DOT_HEIGHT / 2; break;
            case SDLK_DOWN: yVel += DOT_HEIGHT / 2; break;
            case SDLK_LEFT: xVel -= DOT_WIDTH / 2; break;
            case SDLK_RIGHT: xVel += DOT_WIDTH / 2; break;    
        }
    }
    //If a key was released
    else if( event.type == SDL_KEYUP )
    {
        //Adjust the velocity
        switch( event.key.keysym.sym )
        {
            case SDLK_UP: yVel += DOT_HEIGHT / 2; break;
            case SDLK_DOWN: yVel -= DOT_HEIGHT / 2; break;
            case SDLK_LEFT: xVel += DOT_WIDTH / 2; break;
            case SDLK_RIGHT: xVel -= DOT_WIDTH / 2; break;   
        }        
    }
}

void Dot::show()
{
    //Move the dot left or right
    x += xVel;
    
    //If the dot went too far to the left or right
    if( ( x &lt; 0 ) || ( x + DOT_WIDTH &gt; SCREEN_WIDTH ) )
    {
        //move back
        x -= xVel;    
    }
    
    //Move the dot up or down
    y += yVel;
    
    //If the dot went too far up or down
    if( ( y &lt; 0 ) || ( y + DOT_HEIGHT &gt; SCREEN_HEIGHT ) )
    {
        //move back
        y -= yVel;    
    }
    //Show the dot
    apply_surface( x, y, dot, screen );
    
    //While the user hasn't quit
    while( quit == false )
    {
        //Start the frame timer
        fps.start();
        
        //While there's events to handle
        while( SDL_PollEvent( &amp;event ) )
        {
            //Handle events for the dot
            myDot.handle_input();
            
            //If the user has Xed out the window
            if( event.type == SDL_QUIT )
            {
                //Quit the program
                quit = true;
            }
        }
        
        //Fill the screen white
        SDL_FillRect( screen, &amp;screen-&gt;clip_rect, SDL_MapRGB( screen-&gt;format, 0xFF, 0xFF, 0xFF ) );
        
        //Show the dot on the screen
        myDot.show();
        
        //Update the screen
        if( SDL_Flip( screen ) == -1 )
        {
            return 1;    
        }
        
        //Cap the frame rate
        while( fps.get_ticks() &lt; 1000 / FRAMES_PER_SECOND )
        {
            //wait    
        }
    }
}
